package cn.ikun.dhj;

import cn.ikun.dhj.User;
import org.apache.commons.lang3.RandomStringUtils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class DhjApp {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //随机生成指定位数的数字
//        RandomStringUtils.randomAlphabetic(7);随机生成指定位的字母
//       String s= RandomStringUtils.randomNumeric(6);
//        System.out.println(s);
        //创建user实例
        //================================================
        //面向对象
        //================================================
        User u = new User();
        u.setName("weiosang");
        System.out.println(u.getName());
        u.setAge(12);
        System.out.println(u.getAge());
        //================================================
        //面向对象
        //================================================
        //通过类的完整限定名 = 类的包名 +包名
        //通过类的完整限定名来加载某个类对象
        //得到的这个uu相当于user类
        Class<?> UU = Class.forName("cn.ikun.dhj.User");
        Object o = UU.newInstance();
        Method setName = UU.getMethod("setName", String.class);
        setName.invoke(o,"jack");
        Method getName = UU.getMethod("getName");
        Object result = getName.invoke(o);
        System.out.println(result);
        Method setAge = UU.getMethod("setAge", Integer.class);
        setAge.invoke(o,19);
        Method getAge = UU.getMethod("getAge");
        Object result2 = getAge.invoke(o);
        System.out.println(result2);


    }

}
